-- example: type class (this) -- |
|
library ieee;
use ieee.std_logic_1164.all;
package element_pack_typeclass is
type Element is class
class attribute Value: integer;
impure function get_value return integer;
impure function equal(Other: Element'CLASS) return boolean;
impure function different(Other: Element'CLASS) return boolean;
end class Element;
type Element is class body
impure function get_value return integer is
begin
return Value;
end;
impure function equal(Other: Element'CLASS) return boolean is
begin
return (Value = Other.get_value);
end;
impure function different(Other: Element'CLASS) return boolean is
begin
return not this.equal(Other); -- access to current object
end;
end class body Element;
|
base class |
type Child_Of_Element is new class Element with
impure function equal(Other: Element'CLASS) return boolean;
impure function different2(Other: Element'CLASS) return boolean;
end class Child_Of_Element;
type Child_Of_Element is class body
impure function equal(Other: Element'CLASS) return boolean is
-- redefines former method "equal"
begin
return (Value = Other.get_value + 5);
end;
impure function different2(Other: Element'CLASS) return boolean is
begin
return different(Other); -- which "equal" in "different"
-- will be used?
end;
end class body Child_Of_Element;
end package;
|
derived classes |